import vue from '@vitejs/plugin-vue'
import OptimizationPersist from 'vite-plugin-optimize-persist'
import PkgConfig from 'vite-plugin-package-config'

import setupExtend from 'vite-plugin-vue-setup-extend'

import createAutoImport from './auto-import'
import createComponents from './components'
import createSvgIcon from './svg-icon'
import createHtml from './html'

export default function createVitePlugins(viteEnv, isBuild = false) {
  const vitePlugins = [vue(), PkgConfig(), OptimizationPersist(), setupExtend()]

  // 不通过该方式，自动引入会抛异常：Failed to resolve import "undefined"
  vitePlugins.push(createAutoImport())
  vitePlugins.push(createComponents())
  vitePlugins.push(createSvgIcon(isBuild))
  vitePlugins.push(createHtml(viteEnv))
  return vitePlugins
}
